package www.sofn.com.relation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import www.sofn.com.exception.ValidateException;
import www.sofn.com.relation.domain.pojo.MemberRelationPO;

@Service
public class MemberRelationService {

    @Resource
    private MemberRelationMapper mapper;
    @Transactional
    public void  save(MemberRelationPO memberRelationPO){
        final Long selectCount = mapper.selectCount(new LambdaQueryWrapper<MemberRelationPO>().eq(MemberRelationPO::getMemberId, memberRelationPO.getMemberId()));
        if(selectCount>0){
            throw new ValidateException("保存失败：该会员已经绑定过了");
        }
        mapper.insert(memberRelationPO);
    }


    public MemberRelationPO getByMemberId(String memberId){
        final MemberRelationPO memberRelationPO = mapper.selectById(memberId);
        return memberRelationPO;

    }
}
